var isRunning = 0;
var logfile;
var logpath;

function mypath(p) { logpath = p; }

function log(endtime,starttime,title) {
	if (!isRunning) return;
	var s;
	s = parseInt(starttime) +" title \""+title + "\" "+parseInt(endtime-starttime);
	post(s);post();
	logfile.writeline(s);
}

function start() {
	logfile = new File(logpath+"/tv.titler.log."+getTimeStamp()+".txt","write");
	post(logpath+"tv.titler.log."+getTimeStamp()+".txt");
	logfile.open();
	logfile.eof = 0;
	
	logfile.writeline("mcp.eventlist");
	logfile.writeline("#----------------------------------------------------------------");
	logfile.writeline("# remote titler eventlog");
	logfile.writeline("# generated by tv.titler.js from live input");
	logfile.writeline("#");
	logfile.writeline("# job started: "+getTimeStamp());
	logfile.writeline("#----------------------------------------------------------------");
	logfile.writeline("");
	jobstart = new Date();
	isRunning = 1;
	
}

function getTimeStamp() { var now = new Date(); return (now.getFullYear() +'-'+ (now.getMonth() + 1) + '-' + (now.getDate()) +  "-" + now.getHours() + '-' + ((now.getMinutes() < 10) ? ("0" + now.getMinutes()) : (now.getMinutes())) + '-' + ((now.getSeconds() < 10) ? ("0" + now.getSeconds()) : (now.getSeconds()))); }

function stop (){	
	logfile.writeline("");
	isRunning = 0;
	logfile.writeline("#----------------------------------------------------------------");
	logfile.writeline("# job finished: "+getTimeStamp());
	logfile.writeline("# elapsed: "+parseInt((new Date().getTime() - jobstart.getTime())/1000)+ "seconds");
	logfile.writeline("#----------------------------------------------------------------");
	logfile.close();

}
